{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 1: Trimming Values\n",
    "\n",
    "Fill in the blanks so that this program creates a new list\n",
    "containing zeroes where the original list's values were negative\n",
    "and ones where the origina list's values were positive.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "original = [-1.5, 0.2, 0.4, 0.0, -1.3, 0.4]\n",
    "result = []\n",
    "for value in original:\n",
    "    if value < 0:\n",
    "        result.append(0)\n",
    "    else:\n",
    "        result.append(1)\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Challenge 2: String Conditionals\n",
    "\n",
    "Here are our presidents again. Create a list of all the presidents whose last name starts with the letter B.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "presidents_full = [\"George Washington\", \"John Adams\", \"Thomas Jefferson\", \"James Madison\", \"James Monroe\", \\\n",
    "        \"John Quincy Adams\", \"Andrew Jackson\", \"Martin Van Buren\", \"William Henry Harrison\", \"John Tyler\", \\\n",
    "        \"James K. Polk\", \"Zachary Taylor\", \"Millard Fillmore\", \"Franklin Pierce\", \"James Buchanan\", \\\n",
    "        \"Abraham Lincoln\", \"Andrew Johnson\", \"Ulysses S. Grant\", \"Rutherford B. Hayes\", \"James A. Garfield\", \\\n",
    "        \"Chester A. Arthur\", \"Grover Cleveland\", \"Benjamin Harrison\", \"Grover Cleveland\", \"William McKinley\", \\\n",
    "        \"Theodore Roosevelt\", \"William Howard Taft\", \"Woodrow Wilson\", \"Warren G. Harding\", \"Calvin Coolidge\", \\\n",
    "        \"Herbert Hoover\", \"Franklin D. Roosevelt\", \"Harry S. Truman\", \"Dwight D. Eisenhower\", \"John F. Kennedy\", \\\n",
    "        \"Lyndon B. Johnson\", \"Richard Nixon\", \"Gerald Ford\", \"Jimmy Carter\", \"Ronald Reagan\", \"George H. W. Bush\", \\\n",
    "        \"Bill Clinton\", \"George W. Bush\", \"Barack Obama\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "b_pres = []\n",
    "\n",
    "for p in presidents_full:\n",
    "    if p.split()[-1][0] == \"B\":\n",
    "        b_pres.append(p)\n",
    "\n",
    "print(b_pres)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Challenge 3: Find the rhyming words"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Below are the first two stanzas of \"row, row, row your boat\":"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "song = '''Row, row, row your boat\n",
    "Gently down the stream,\n",
    "Merrily merrily, merrily, merrily\n",
    "Life is but a dream.\n",
    "\n",
    "Row, row, row your boat\n",
    "Gently down the brook,\n",
    "If you catch a little fish \n",
    "Let it off the hook.'''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Using string methods, for loops, and conditionals, write some code to `print` only the rhyming words. We'll be simplistic and assume it rhymes if the last 3 characters are the same.\n",
    "\n",
    "(HINT: first remove punctuation using `punctation` below)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from string import punctuation\n",
    "\n",
    "for char in \".,\":\n",
    "    song = song.replace(char, \"\")\n",
    "\n",
    "for w in song.split():\n",
    "    for other_w in song.split():\n",
    "        if w[-3:] == other_w[-3:] and w.lower() != other_w.lower():\n",
    "            print(w)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Challenge 4: Acrostics"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In poetry, an acrostic is a message created by taking certain letters in a pattern over lines. One 9th century German writer, Otfrid of Weissenburg, was notorius for his early use of acrostics, one of which is in the text below: *Salomoni episcopo Otfridus*. His message can be found by taking the first character of every other line. Print Otfrid's message! \n",
    "\n",
    "(HINT: remember what % does, lookup \"enumerate\")\n",
    "\n",
    "Source: http://titus.uni-frankfurt.de/texte/etcs/germ/ahd/otfrid/otfri.htm"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = '''si sálida gimúati      sálomones gúati, \n",
    "     ther bíscof ist nu édiles      kóstinzero sédales; \n",
    "     allo gúati gidúe thio sín,      thio bíscofa er thar hábetin, \n",
    "     ther ínan zi thiu giládota,      in hóubit sinaz zuívalta! \n",
    "     lékza ih therera búachi      iu sentu in suábo richi, \n",
    "     thaz ir irkíaset ubar ál,      oba siu frúma wesan scal; \n",
    "     oba ir hiar fíndet iawiht thés      thaz wírdig ist thes lésannes: \n",
    "     iz iuer húgu irwállo,      wísduames fóllo. \n",
    "     mir wárun thio iuo wízzi      ju ófto filu núzzi, \n",
    "     íueraz wísduam;      thes duan ih míhilan ruam. \n",
    "     ófto irhugg ih múates      thes mánagfalten gúates, \n",
    "     thaz ír mih lértut hárto      íues selbes wórto. \n",
    "     ni thaz míno dohti      giwérkon thaz io móhti, \n",
    "     odo in thén thingon      thio húldi so gilángon; \n",
    "     iz datun gómaheiti,      thio íues selbes gúati, \n",
    "     íueraz giráti,      nales míno dati. \n",
    "     emmizen nu ubar ál      ih druhtin férgon scal, \n",
    "     mit lón er iu iz firgélte      joh sínes selbes wórte; \n",
    "     páradyses résti      gébe iu zi gilústi; \n",
    "     ungilónot ni biléip      ther gotes wízzode kleip. \n",
    "     in hímilriches scóne      so wérde iz iu zi lóne \n",
    "     mit géltes ginúhti,      thaz ír mir datut zúhti. \n",
    "     sínt in thesemo búache,      thes gómo theheiner rúache; \n",
    "     wórtes odo gúates,      thaz lích iu iues múates: \n",
    "     chéret thaz in múate      bi thia zúhti iu zi gúate, \n",
    "     joh zellet tház ana wánc      al in íuweran thanc. \n",
    "     ofto wírdit, oba gúat      thes mannes júngoro giduat, \n",
    "     thaz es líwit thráto      ther zúhtari gúato. \n",
    "     pétrus ther rícho      lono iu es blídlicho, \n",
    "     themo zi rómu druhtin gráp      joh hús inti hóf gap; \n",
    "     óbana fon hímile      sént iu io zi gámane \n",
    "     sálida gimýato      selbo kríst ther gúato! \n",
    "     oba ih irbálden es gidár,      ni scal ih firlázan iz ouh ál, \n",
    "     nub ih ío bi iuih gerno      gináda sina férgo, \n",
    "     thaz hóh er iuo wírdi      mit sínes selbes húldi, \n",
    "     joh iu féstino in thaz múat      thaz sinaz mánagfalta gúat; \n",
    "     firlíhe iu sines ríches,      thes hohen hímilriches, \n",
    "     bi thaz ther gúato hiar io wíaf      joh émmizen zi góte riaf; \n",
    "     rihte íue pédi thara frúa      joh míh gifúage tharazúa, \n",
    "     tház wir unsih fréwen thar      thaz gotes éwiniga jár, \n",
    "     in hímile unsih blíden,      thaz wízi wir bimíden; \n",
    "     joh dúe uns thaz gimúati      thúruh thio síno guati! \n",
    "     dúe uns thaz zi gúate      blídemo múate! \n",
    "     mit héilu er gibóran ward,      ther io thia sálida thar fand, \n",
    "     uuanta es ni brístit furdir      (thes gilóube man mír), \n",
    "     nirfréwe sih mit múatu      íamer thar mit gúatu. \n",
    "     sélbo krist ther guato      firlíhe uns hiar gimúato, \n",
    "     wir íamer fro sin múates      thes éwinigen gúates!'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "message = \"\"\n",
    "for i,l in enumerate(text.split(\"\\n\")):\n",
    "    if i % 2 == 0:\n",
    "        message += l.split()[0][0]\n",
    "\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Otfrid was more skillful than to settle for the first letter of every other line. What happens if you extract the last letter of the last word of each line, for every other line starting on the second line?\n",
    "\n",
    "(HINT: first remove punctuation and lookup \"enumerate\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "for char in punctuation:\n",
    "    text = text.replace(char, \"\")\n",
    "\n",
    "message = \"\"\n",
    "for i,l in enumerate(text.split(\"\\n\")):\n",
    "    if i % 2 != 0:\n",
    "        message += l.split()[-1][-1]\n",
    "\n",
    "print(message)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
